package com.fusion.core.comm.rpc;

import com.fusion.core.comm.RPC;

import java.io.Serializable;

/**
 * A persistent RPC is an rpc that can be sent using NetworkManager.sendPersistantly(...). It is guaranteed to
 * arrive at its destination. Even if the destination will not be connected for several days and even if
 * the application is restarted.
 *
 * @author SwethaShivakumar 
 * Project: fusion
 * Date: Mar 7, 2009
 * URL: http://fusionwiki.co.cc
 * Mail Me At: shiva@fusionproject.co.cc
 */
public abstract class PersistantRPC extends RPC implements Serializable {
	private int destinationGuid;
    private long timestamp;
    protected boolean hasBeenQueuedForLaterSend;

    public int getDestinationGuid() {
        return destinationGuid;
    }

    public void setDestinationGuid(int destinationGuid) {
        this.destinationGuid = destinationGuid;
    }

    public void resetTimestamp() {
        timestamp = System.currentTimeMillis();
    }

    /**
     * Return true if this PersistantRPC is older than a month.
     */
    public boolean hasExpired() {
        return System.currentTimeMillis() - timestamp > ((long)1000)*60*60*24*31;
    }

    public void notifyRPCQueuedForLaterSend() {
        hasBeenQueuedForLaterSend = true;
    }
}
